var t = require("../../../@babel/runtime/helpers/defineProperty"), a = getApp();

Component({
    properties: {
        datas: {
            type: null
        },
        component_id: {
            type: null
        },
        shareId: {
            type: null,
            value: ""
        }
    },
    data: {
        emptyImage: "https://mini-app-img-1251768088.cos.ap-guangzhou.myqcloud.com/image.png",
        clientWidth: "375",
        goods: [],
        radio: "",
        prizeIndex: 999,
        arrNum: [ 0, 1, 2, 3, 7, 11, 15, 14, 13, 12, 8, 4 ],
        clickFlage: !0,
        prizeInfoShow: !1,
        noPrizeShow: !1,
        havePrizeShow: !1,
        haveLottery: !1,
        timer1: "",
        timer2: "",
        s1: "",
        s2: -1,
        lotteryId: "",
        hasRecord: !1,
        remainingTimes: 0,
        prizeList: [],
        prizeLevel: "",
        prizeName: "",
        prizeUrl: "",
        timeFlag: 0,
        startStatus: 1,
        prizerListBol: !1,
        activityModel: {},
        countdown_time: [],
        result_arr: [],
        usable: "",
        success_app_url: ""
    },
    lifetimes: {
        attached: function() {},
        moved: function() {},
        detached: function() {}
    },
    attached: function() {},
    ready: function() {
        this.setData({
            clientWidth: wx.getSystemInfoSync().windowWidth
        });
        var t = wx.getStorageSync("yz_basic_info");
        t.home.memberinfo && this.setData({
            usable: t.home.memberinfo.usable
        }), this.data.datas.lottery && this.data.datas.lottery.name && this.initData(), 
        this.properties.shareId && this.getData();
    },
    pageLifetimes: {
        show: function() {},
        hide: function() {},
        resize: function() {}
    },
    methods: {
        toUrl: function() {
            wx.navigateTo({
                url: "/packageC/orders/LotteryRecord/LotteryRecord?lotteryId=" + this.data.lotteryId
            });
        },
        onChange: function(t) {
            this.setData({
                radio: t.detail
            });
        },
        closePop: function() {
            this.setData({
                show: !1
            });
        },
        confirmGoods: function() {
            this.setData({
                show: !1
            }), this.data.radio && wx.navigateTo({
                url: "/packageA/detail_v2/detail_v2?id=" + this.data.radio
            });
        },
        getData: function() {
            console.log("111111");
            var e = this, i = a.getNetAddresss("plugin.lucky-draw.frontend.draw.index");
            this.properties.shareId && (i += "&share_id=" + this.properties.shareId), a._getNetWork({
                url: i,
                data: {
                    lotteryId: this.data.lotteryId
                },
                success: function(a) {
                    var i = a.data;
                    1 == i.result && (e.setData(t({
                        activityModel: i.data.activityModel
                    }, "datas.list.point.credit1", i.data.point.credit1)), i.data.love && e.setData({
                        usable: i.data.love[0]
                    }));
                },
                fail: function(t) {
                    console.log(t);
                }
            });
        },
        initData: function() {
            if (this.data.datas.list) {
                this.setData({
                    result_arr: this.data.datas.list.result_arr,
                    activityModel: this.data.datas.list.activityModel,
                    success_app_url: this.data.datas.list.activityModel.success_app_url,
                    countdown_time: this.data.datas.list.activityModel.countdown_time,
                    lotteryId: this.data.datas.list.activityModel.id,
                    remainingTimes: this.data.datas.list.surplus_time,
                    goods: this.data.datas.list.goods
                }), this.data.goods && this.data.goods.length > 0 && this.setData({
                    radio: this.data.goods[0].id
                }), this.data.result_arr.forEach(function(t) {
                    t.bgSrc = "https://mini-app-img-1251768088.cos.ap-guangzhou.myqcloud.com/lottery/item_bg.png";
                }), this.data.result_arr.splice(5, 0, " "), this.data.result_arr.splice(6, 0, " "), 
                this.data.result_arr.splice(9, 0, " "), this.data.result_arr.splice(10, 0, " "), 
                this.setData({
                    prizeList: this.data.result_arr
                });
                var t = this.data.prizeList[4];
                this.setData({
                    "prizeList[4]": this.data.prizeList[7],
                    "prizeList[7]": t
                }), t = this.data.prizeList[12], this.setData({
                    "prizeList[12]": this.data.prizeList[13],
                    "prizeList[13]": t
                }), t = this.data.prizeList[14], this.setData({
                    "prizeList[14]": this.data.prizeList[15],
                    "prizeList[15]": t
                }), this.statusFun(Date.parse(new Date()) / 1e3, this.data.countdown_time[0], this.data.countdown_time[1]);
            }
        },
        statusFun: function(t, a, e) {
            t < a ? this.setData({
                startStatus: 0
            }) : t > a && t < e ? this.setData({
                startStatus: 1
            }) : t > e && this.setData({
                startStatus: 2
            });
        },
        prizeZhuan: function() {
            var t = this, e = this;
            if (this.setData({
                prizeIndex: 0
            }), this.data.remainingTimes > 0) {
                if (this.data.clickFlage) if (1 === this.data.startStatus) {
                    this.setData({
                        clickFlage: !1,
                        timer1: setInterval(function() {
                            t.move();
                        }, 100)
                    });
                    var i = a.getNetAddresss("plugin.lucky-draw.frontend.draw.doDraw");
                    a._getNetWork({
                        url: i,
                        data: {
                            lotteryId: this.data.lotteryId
                        },
                        success: function(t) {
                            var a = t.data;
                            1 == a.result ? (e.setData({
                                remainingTimes: e.data.remainingTimes - 1
                            }), a.data.result ? (e.setData({
                                hasRecord: !0,
                                prozeLevel: a.data.result.item,
                                prizeName: a.data.result.prize,
                                prizeUrl: a.data.result.thumb_url
                            }), e.getData()) : (e.setData({
                                hasRecord: !1,
                                prozeLevel: a.data.item,
                                prizeName: a.data.prize,
                                prizeUrl: a.data.thumb_url,
                                empty_prize_prompt: a.data.empty_prize_prompt
                            }), e.getData()), setTimeout(function() {
                                clearInterval(e.data.timer1), e.lowSpeed();
                            }, 1200)) : (wx.showModal({
                                title: "提示",
                                content: a.msg,
                                showCancel: !1,
                                success: function(t) {
                                    t.confirm && e.data.goods && e.data.goods.length > 0 && e.setData({
                                        show: !0
                                    });
                                }
                            }), e.setData({
                                clickFlage: !0
                            }), clearInterval(e.data.timer1), clearInterval(e.data.timer2));
                        },
                        fail: function(t) {
                            console.log(t);
                        }
                    });
                } else 0 === this.data.startStatus ? wx.showToast({
                    icon: "none",
                    title: "活动尚未开始",
                    duration: 1500
                }) : 2 === this.data.startStatus && wx.showToast({
                    icon: "none",
                    title: "活动已经结束",
                    duration: 1500
                });
            } else this.setData({
                prizeInfoShow: !0,
                haveLottery: !0
            });
        },
        lowSpeed: function() {
            var t = this;
            clearInterval(this.data.timer1), this.setData({
                clickFlage: !1,
                timer2: setInterval(function() {
                    t.move();
                }, 300)
            }), setTimeout(function() {
                t.setData({
                    s2: t.data.prozeLevel
                });
            }, 900);
        },
        move: function() {
            0 === this.data.prizeIndex ? this.setData({
                prizeIndex: this.data.prizeIndex + 1
            }) : 12 === this.data.prizeIndex ? this.setData({
                prizeIndex: 0
            }) : this.setData({
                prizeIndex: this.data.prizeIndex + 1
            }), -1 !== this.data.s2 && this.data.prizeList[this.data.arrNum[this.data.prizeIndex]] && this.data.prizeList[this.data.arrNum[this.data.prizeIndex]].item == this.data.s2 && (clearInterval(this.data.timer1), 
            clearInterval(this.data.timer2), this.stop()), this.setData({
                timeFlag: this.data.timeFlag + 100
            }), this.data.timeFlag >= 1e4 && !this.data.prizeName && (clearInterval(this.data.timer1), 
            clearInterval(this.data.timer2), wx.showToast({
                icon: "none",
                title: "当前抽奖人数过多，稍后再来",
                duration: 1500
            }), this.setData({
                clickFlage: !0
            }));
        },
        stop: function() {
            this.setData({
                s2: -1,
                clickFlage: !1
            }), this.prizeInfo();
        },
        prizeInfo: function() {
            var t = this;
            setTimeout(function() {
                t.setData({
                    clickFlage: !0
                }), t.data.hasRecord ? t.setData({
                    prizeInfoShow: !0,
                    havePrizeShow: !0,
                    noPrizeShow: !1
                }) : t.setData({
                    prizeInfoShow: !0,
                    noPrizeShow: !0,
                    havePrizeShow: !1
                }), t.data.noPrizeShow && wx.showModal({
                    title: "提示",
                    content: "".concat(t.data.empty_prize_prompt || "很遗憾，您没有中奖"),
                    showCancel: !1
                }), t.data.havePrizeShow && wx.showModal({
                    title: "提示",
                    content: "恭喜您抽中".concat(t.data.prizeName),
                    showCancel: !1,
                    success: function(a) {
                        a.confirm && wx.navigateTo({
                            url: t.data.activityModel.success_mini_url,
                            fail: function(t) {}
                        });
                    }
                }), t.data.haveLottery && wx.showModal({
                    title: "提示",
                    content: "您已经抽过奖啦，不要太贪心哦！",
                    showCancel: !1
                });
            }, 800);
        }
    }
});